package cate.game.admin.menu.guild;


import cate.common.table.d.GDGuild;
import cate.game.GameBody;
import cate.game.admin.menu.MenuSetup;
import cate.game.role.res.guild.po.GuildPO;
import cate.game.role.res.guild.po.fairyland.core.GuildFairylandBossPO;


public class GuildMenu extends MenuSetup {

    public GuildMenu(GameBody gameBody) {
        super("协会");
        reg(gameBody, "保存公会数据", 0, "嘿", (role, params) -> {
            int n = role.getGame().res.guild.save();
            gameBody.notice.message(role, "保存n="+n);
        });

        reg(gameBody, "增加协会经验", 1, "【参数1】+活跃度",
                (role, params) -> {
                    if (params.isEmpty()) {
                        gameBody.notice.message(role, "参数不能少于1个!");
                        return;
                    }
                    int num = Integer.parseInt(params.get(0));
                    if (role.getRes().guild.checkGuild().ok())
                        role.getRes().guild.getGuild().basic.gmAddExp(num);//方法内部已经通知
                    else
                        gameBody.notice.message(role, "没有加入的协会");
                    gameBody.notice.message(role, "已经改变了你的协会经验!");
                });

        reg(gameBody, "公会技能无消耗重置", 0, "", (role, params) -> {
            role.getRes().guild.skill.gmRebuildAll();
            role.getGame().notice.message(role, "设置成功拉");
        });

        reg(gameBody, "公会技能升到最高级别", 1, "类型(表格中类型项)", (role, params) -> {
            role.getRes().guild.skill.gmNormalHighestLevel(Byte.parseByte(params.get(0)));
            role.getGame().notice.message(role, "设置成功拉");
        });


        reg(gameBody, "清除我个人的协会数据", 0, "",
                (role, params) -> {
                    if (role.getRes().guild.checkGuild().ok())
                        role.getRes().guild.getGuild().member.removeMember(gameBody, role.getUid());
                    role.getRes().guild.noticeUpdate();
                    gameBody.notice.message(role, "设置成功");
                });


        reg(gameBody, "协会等级设置", 1, "【参数1】等级",
                (role, params) -> {
                    role.getRes().guild.getGuild().basic.level = Integer.parseInt(params.get(0));
                    role.getRes().guild.noticeUpdate();
                    gameBody.notice.message(role, "设置成功");
                });


        reg(gameBody, "协会会长id设为null", 0, "用于测试修复逻辑",
                (role, params) -> {
                    role.getRes().guild.getGuild().basic.presidentId = null;
                    gameBody.notice.message(role, "设置成功");
                });

        reg(gameBody, "协会全员设置成成员", 0, "用于测试修复逻辑",
                (role, params) -> {
                    role.getRes().guild
                            .getGuild()
                            .member
                            .list
                            .forEach(a -> a.performance.changePos(GDGuild.position.MEMBER));
                    gameBody.notice.message(role, "设置成功");
                });

        reg(gameBody, "清空我的退会惩罚时间", 0, "",
                (role, params) -> {
                    role.getRes().guild.withdrawalTime = 0L;
                    gameBody.notice.message(role, "清空成功");
                });

        reg(gameBody, "将我设置为会长", 0, "",
                (role, params) -> {
                    // 把职位设成会长
                    role.getRes().guild.performance.position = GDGuild.position.PRESIDENT;
                    role.getRes().guild.getGuild().basic.presidentId = role.getUid();
                    role.getRes().guild.getGuild().basic.presidentName = role.getBase().name;
                    role.getRes().guild.getGuild().basic.srvIdOriginPresident = role.getBase().srvIdOrigin;

                    // 成员列表里的职位也改一下
                    role.getRes().guild.getGuild().member.getMember(role.getUid()).performance.position = GDGuild.position.PRESIDENT;
                    role.getRes().guild.getGuild().member.noticeUpdate(role);
                    gameBody.notice.message(role, "设置成功");
                });


        reg(gameBody, "我的协会商店重置", 0, "",
                (role, params) -> {
                    if (!role.getRes().guild.checkGuild().ok())
                        gameBody.notice.message(role, "没有协会");
                    role.getRes().guild.mall.list = null;
                    role.getRes().guild.mall.initialize(role);
                    gameBody.notice.message(role, "设置成功");
                });
        reg(gameBody, "清除所有协会", 0, "",
                (role, params) -> {
                    gameBody.res.guild.fixGuild();
                    logger.info(String.format("玩家%s解散了所有协会,时间:%d", role.getBase().uid, System.currentTimeMillis()));
                });
        reg(gameBody, "协会boss 重置号角时间", 0, "",
                (role, params) -> {
                    if (!role.getRes().guild.checkGuild().ok())
                        gameBody.notice.message(role, "没有协会");
                    role.getFarm().guildBoss.lastHornTime = 0L;
                    gameBody.notice.message(role, "设置成功");
                });
        reg(gameBody, "公会加点活跃度", 1, "",
                (role, params) -> {
                    if (!role.getRes().guild.checkGuild().ok()) {
                        gameBody.notice.message(role, "没有协会");
                        return;
                    }
                    int act = Integer.parseInt(params.get(0));
                    role.getRes().guild.getGuild().active.addActive(act);
                    gameBody.notice.message(role, "添加成功!");
                });
        reg(gameBody, "个人加点活跃度", 1, "",
                (role, params) -> {
                    if (!role.getRes().guild.checkGuild().ok()) {
                        gameBody.notice.message(role, "没有协会");
                        return;
                    }
                    int act = Integer.parseInt(params.get(0));
                    role.getRes().guild.active.addExp(act);
                    role.getRes().guild.active.noticeUpdate();
                    gameBody.notice.message(role, "添加成功!");
                });
        reg(gameBody, "公会秘境BOSS血量见底", 0, "",
                (role, params) -> {
                    if (!role.getRes().guild.checkGuild().ok()) {
                        gameBody.notice.message(role, "没有协会");
                        return;
                    }
                    if (role.getRes().guild.getGuild().fairyland.openingBossType == 0) {
                        gameBody.notice.message(role, "公会秘境BOSS没开");
                        return;
                    }
                    GuildFairylandBossPO bossPO = role.getRes().guild.getGuild().fairyland.bossPOMap.get(role.getRes().guild.getGuild().fairyland.openingBossType);
                    if (bossPO == null) {
                        gameBody.notice.message(role, "公会秘境BOSS没开");
                        return;
                    }
                    bossPO.curHp = 10;
                    role.getFarm().guildFairyland.noticeUpdate();
                });
        reg(gameBody, "公会清除入会时间限制", 0, "",
                (role, params) -> {
                    role.getRes().guild.joinTime = 0;
                    role.getRes().guild.noticeUpdate();
                });
        reg(gameBody, "公会宝库清除日志", 0, "",
                (role, params) -> {
                    GuildPO guild = role.getRes().guild.getGuild();
                    if (guild == null) {
                        return;
                    }
                    guild.treasureHouse.logPO.logs.clear();
                    guild.treasureHouse.logPO.noticeUpdate(role);
                });
    }
}
